import java.util.*;
import java.text.SimpleDateFormat;

public class SalesService {
    public SalesService() {
        // 不再需要ScheduleService依赖
    }
    public void showTodaySales() {
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
        boolean found = false;
        for (Schedule s : Schedule.getSchedules()) {
            if (s.getTimeSlot().startsWith(today)) {
                Hall hall = s.getHall();
                Seat[][] seats = hall.getSeats();
                int sold = 0;
                for (int i = 0; i < hall.getRows(); i++) {
                    for (int j = 0; j < hall.getSeatsPerRow(); j++) {
                        if (seats[i][j].isOccupied()) sold++;
                    }
                }
                double total = sold * s.getPrice();
                System.out.printf("影片: %s, 场次: %s, 售票数: %d, 单价: %.2f, 总票价: %.2f\n",
                    s.getMovie().getName(), s.getTimeSlot(), sold, s.getPrice(), total);
                found = true;
            }
        }
        if (!found) {
            System.out.println("今日暂无销售数据。");
        }
    }
    public void showWeekSales() {
        Calendar cal = Calendar.getInstance();
        int week = cal.get(Calendar.WEEK_OF_YEAR);
        int year = cal.get(Calendar.YEAR);
        boolean found = false;
        for (Schedule s : Schedule.getSchedules()) {
            try {
                cal.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(s.getTimeSlot()));
            } catch (Exception e) { continue; }
            int sWeek = cal.get(Calendar.WEEK_OF_YEAR);
            int sYear = cal.get(Calendar.YEAR);
            if (sWeek == week && sYear == year) {
                Hall hall = s.getHall();
                Seat[][] seats = hall.getSeats();
                int sold = 0;
                for (int i = 0; i < hall.getRows(); i++) {
                    for (int j = 0; j < hall.getSeatsPerRow(); j++) {
                        if (seats[i][j].isOccupied()) sold++;
                    }
                }
                double total = sold * s.getPrice();
                System.out.printf("影片: %s, 场次: %s, 售票数: %d, 单价: %.2f, 总票价: %.2f\n",
                    s.getMovie().getName(), s.getTimeSlot(), sold, s.getPrice(), total);
                found = true;
            }
        }
        if (!found) {
            System.out.println("本周暂无销售数据。");
        }
    }
    public void showMonthSales() {
        String month = new SimpleDateFormat("yyyy-MM").format(new java.util.Date());
        boolean found = false;
        for (Schedule s : Schedule.getSchedules()) {
            if (s.getTimeSlot().startsWith(month)) {
                Hall hall = s.getHall();
                Seat[][] seats = hall.getSeats();
                int sold = 0;
                for (int i = 0; i < hall.getRows(); i++) {
                    for (int j = 0; j < hall.getSeatsPerRow(); j++) {
                        if (seats[i][j].isOccupied()) sold++;
                    }
                }
                double total = sold * s.getPrice();
                System.out.printf("影片: %s, 场次: %s, 售票数: %d, 单价: %.2f, 总票价: %.2f\n",
                    s.getMovie().getName(), s.getTimeSlot(), sold, s.getPrice(), total);
                found = true;
            }
        }
        if (!found) {
            System.out.println("本月暂无销售数据。");
        }
    }
} 